import {
    Actions
} from 'react-native-router-flux';

import getRoute from './getRoute';

const isLogin = () => !!getUserId();

import * as Event from './../utils/event';

import getUserId from './../utils/userId';

let deepJump:any = null;

export default (deep:any):any => {
    deepJump = deep;
    if (isLogin()) {
        deepAction()
    }
    return false
}

const deepAction = () => {
    if (!deepJump) {
        return false;
    }

    const {
        action,
        params
    } = deepJump;

    const {
        outJmp
    } = getRoute(action);

    if (outJmp === true) {
        Actions[action]({
            ...params,
            switchModal: true
        })
    }

    deepJump = null;
}

Event.add(Event.ON_ENTER_HOME, deepAction);